package ms;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class RegesiterDayInC {

	int n, m, k;

	static class Student {
		int stuid, time, p, ctp;
		List<Integer> room;
		List<Integer> work_t;

		public void get(){
	        ctp=0;
//	        scanf("%d%d%d",&stuid,&time,&p);
	        Scanner scanner = new Scanner(System.in);
	        stuid = scanner.nextInt();
	        time = scanner.nextInt();
	        p = scanner.nextInt();
	        for(int i=0;i<p;i++){
	            int x,y;
//	            scanf("%d%d",&x,&y);
	            x = scanner.nextInt();
	            y = scanner.nextInt();
	            room.add(x);
	            work_t.add(y);
	        }
	        scanner.close();
	    }
	};

	static class Wait implements Comparator<Wait> {
		int time, stuid, idx, roomid;

		Wait() {
		}

		Wait(int a, int b, int c, int d) {
			time = a;
			stuid = b;
			idx = c;
			roomid = d;
		}

		@Override
		public int compare(Wait o1, Wait o2) {
			if (o1.time != o2.time)
				return o1.time < o2.time ? -1 : 1;
			return stuid < o2.stuid ? -1 : 1;
		}
	};

	static int finish[] = new int[1005];

	public static void main(){
	    int n, m, k;
	    Scanner scanner = new Scanner(System.in);
	    n = scanner.nextInt();
	    m = scanner.nextInt();
	    k = scanner.nextInt();
	    Student[] stu = new Student[n];
	    for(int i=0;i<n;i++)stu[i].get();
	    Set<Wait> event = new HashSet<>();
	    for(int i=0;i<n;i++){
	        Student x = stu[i];
	        event.add(new Wait(x.time + k, x.stuid, i, x.room.get(x.ctp)));
	    }
	    
	    while(event.size() > 0){
	        Iterator<Wait> it = event.iterator();
	        Wait x = it.next();
	        event.remove(x);
			int rid = x.roomid;
			int sidx = x.idx;
	        Student sx = stu[sidx];
	        
	        finish[rid] = Math.max(finish[rid], x.time)+ sx.work_t.get(sx.ctp);
	        sx.time=finish[rid];
	        sx.ctp++;
	        if(sx.ctp<sx.p){
	            int roomid=sx.room.get(sx.ctp);
	            event.add(new Wait(sx.time+k,sx.stuid,sidx,sx.room.get(sx.ctp)));
	        }
	    }
	    
	    for(int i=0;i<n;i++){
	        System.out.printf("%d\n",stu[i].time);
	    }
	}
}
